﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Testing.aspx.cs" Inherits="ml_testing_BingTrans.Testing" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript" src="jquery-1.7.1.js"></script>
    <script type="text/javascript">
    jQuery.bingTranslate = function(bingAppId, textToTranslate, fromLanguage, toLanguage, 
                                callbackFunctions) 
    {
        var data = 
        {
            appid   : bingAppId,
            to      : toLanguage,
            from    : fromLanguage,
            text    : textToTranslate
        };

    	var defaultCallbacks =
        {
    	    success: function(data, status)
    	    {
    		    jQuery.log('success (status: ' + status + ')');
    		    jQuery.log('data: ' + data);
    	    },
    	    complete: function(request, status)
    	    {
    		    jQuery.log('complete (status: ' + status + ')');
    	    },
    	    error: function(request, status, error)
    	    {
    		    jQuery.log('error (status: ' + status + ')');
    		    jQuery.log('error: ' + error);
    	    },
    	    jsonpCallback: 'ajaxTranslateCallback'
        };
        callbackFunctions = jQuery.extend({}, defaultCallbacks, callbackFunctions); 
     
        jQuery.ajax({
                url             : 'http://api.microsofttranslator.com/V2/Ajax.svc/Translate',
                data            : data,
                dataType        : 'jsonp',
                jsonp           : 'oncomplete',
                jsonpCallback   : callbackFunctions.jsonpCallback,
                success         : callbackFunctions.success,
                complete        : callbackFunctions.complete,
                error           : callbackFunctions.error
        });
    }
    </script>
    
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Source text in English ("en"):
        <textarea id="sourceContent" style="width: 100%; height: 200px;">
        Fly beast upon let isn't forth give him above itself grass so were Let. 
        Fruit likeness behold female wherein, she'd form winged bring him Lights 
        there together two saw seas morning rule made night fifth days morning. 
        Sea saw yielding good.
        (dummy text generated with http://www.dummytextgenerator.com)
        </textarea>
        <button id="translate">
            Translate</button>
        Output text in Spanish ("es"):
        <textarea id="outputContent" style="width: 100%; height: 200px;">
        </textarea>
    </div>
    <script type="text/javascript">

        $(document).ready(function()
        {
        	alert('MLML000');
            // bind button click event:
        	alert($('#tranlate').)
            $('#tranlate').click(function(event)
            {
            	alert('MLML001');
            	
                event.preventDefault();
                var sourceContent     = $('#sourceContent').val();
     
                // the success callback function will be called from out
                // bingTranslate method when the translation is successful
                // we output the result (data) in the outputContent textarea
            	var callbackFunctions =
                {
                	success: function(data, status)
                	{
                		$('#outputContent').val(data);
                	}
                };

            	alert('MLML');
     
                // perform the actial Bing translation request:
                $.bingTranslate("C1D1CDEB53FDFCC57E7F911E872CD85B0ACF46E3", sourceContent, 
                                "en", "es", callbackFunctions);
            });
        });
    
    </script>
    </form>
    
</body>
</html>
